/*
 *  FNT.h
 *  SCMS
 *
 *  Created by poiuy_qwert on 14/07/09.
 *
 */

#pragma once

#include "Exception.h"
#include "Pack.h"
#include "Palettes.h"
#include "BMP.h"

#include <vector>
#include <cstring>

struct FNT_HEADER {
	unsigned char sign[4], lowIndex, highIndex, maxWidth, maxHeight;
};
struct FNT_CHR_HEADER {
	unsigned char width, height, xOffset, yOffset;
};

class FNT {
	unsigned char lowIndex, width, height;
	vector<unsigned char*> letters;
public:
	FNT()
		: lowIndex(0),width(0),height(0) {}
	FNT(vector<unsigned char*> letters, char width, char height, char low = 32);
	FNT(const char *filename)
		{ this->open_file(filename); }
	FNT(const char *buffer, int size)
		{ this->open_data(buffer, size); }
	~FNT()
		{ this->close(); }

	static FNT_CHR_HEADER* letter_dims(unsigned char* letter, char width, char height);

	void open_file(const char *filename);
	void open_data(const char *buffer, int size);
	void export_file(const char *filename, Palette *palette);
	BMP* export_data(Palette *palette);
	void save_file(const char *filename);
	char* save_data(int &size);

	unsigned char get_low()
		{ return this->lowIndex; }
	unsigned char get_width()
		{ return this->width; }
	unsigned char get_height()
		{ return this->height; }
	unsigned char* get_letter(int n);
	void set_letter(int n, unsigned char *letter);
	
	void close();
};